﻿CREATE TRIGGER [dbo].[TRG_CONTRACT_DELETE_PID]
ON dbo.CONTRACT
FOR DELETE
AS
BEGIN
    SET NOCOUNT ON;

	DELETE FROM PID WHERE ID IN (SELECT PID FROM DELETED)
	/* IF UPDATE() ... */

END
/*
ALTER TRIGGER [dbo].[TRG_CONTRACT_CREATE_PID]
   ON  dbo.CONTRACT
   AFTER INSERT
AS
BEGIN
    SET NOCOUNT ON;

    INSERT INTO dbo.PID (CONTR_ID) (SELECT ID FROM CONTRACT WHERE ID IN (SELECT ID FROM INSERTED));

	UPDATE CONTRACT
    SET PID = (SELECT ID FROM PID WHERE CONTR_ID IN (SELECT ID FROM INSERTED))
    WHERE ID IN (SELECT ID FROM INSERTED);

END
*/